<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>

    //年终奖策略，也可以将S,A,B,C四个函数拆分成一个个独立函数
    const bonusStrategy = {
        'S': function (salary) {
            return salary * 4
        },
        'A': function (salary) {
            return salary * 3
        },
        'B': function (salary) {
            return salary * 2
        },
        'C': function (salary) {
            return salary
        }
    }

    //写法1
    //根据不同绩效级别，获取不同的奖金
    const calcBonus = function (level, baseSalary) {
        //使用if-else的写法
        /*if (level === 'S') {
            return baseSalary * 4;
        } else if (level === 'A') {
            return baseSalary * 3;
        } else if (level === 'B') {
            return baseSalary * 2;
        } else if (level === 'C') {
            return baseSalary;
        }*/
        return bonusStrategy[level](baseSalary);
    }

    //写法2
    const calcBonus2 = function (func, baseSalary) {
        return func(baseSalary);
    }

    console.log(calcBonus2(bonusStrategy.A, 1000));
</script>
</body>
</html>